#include "GameResourceManager.h"

#include <fstream>

#include "GameException.h"

GameResourceManager::GameResourceManager()
{
	std::fstream file( "resources/resources.txt", std::fstream::in );

	if ( !file.is_open() )
	{
		throw GameException( "File 'resources/resources.txt' missing" );
	}

	while ( !file.eof() )
	{
		std::string line = "";
		std::getline( file, line );

		if ( line[ 0 ] == '#' )
		{
			continue;
		}

		size_t seperator = line.find( "=" );
		if ( seperator == std::string::npos )
		{
			continue;
		}

		std::string name  = line.substr( 0, seperator );
		std::string value = line.substr( seperator + 1 );

		resources.insert( std::pair< std::string, std::string >( name, value ) );
	}
}

std::map< std::string, std::string >& GameResourceManager::GetResourceList()
{
	return resources;
}

std::string& GameResourceManager::operator[] ( const std::string& index )
{
	return resources[ index ];
}
